PREFIX = /usr/local
CFLAGS += -Wall -g -std=gnu99 
LDFLAGS += -L/opt/mx287/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/lib -L/opt/mx287/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/lib/gcc/arm-fsl-linux-gnueabi/4.4.4/

CC=$(CROSS_COMPILE)gcc
INSTALL = install

OBJS =	dev_table.o	\
	i2c.o		\
	init.o		\
	main.o		\
	port.o		\
	serial_common.o	\
	serial_platform.o	\
	stm32.o		\
	utils.o

OBJS2 =	dev_table.o	\
	i2c.o		\
	init.o		\
	cgi-olp-main.o		\
	port.o		\
	serial_common.o	\
	serial_platform.o	\
	stm32.o		\
	cjson.o \
	utils.o

LIBOBJS = parsers/parsers.a  -lpthread

all: stm32flash

serial_platform.o: serial_posix.c serial_w32.c

parsers/parsers.a:
	cd parsers && $(MAKE) parsers.a

stm32flash: $(OBJS) $(LIBOBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBOBJS)


query-cache.elf: $(OBJS2) $(LIBOBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS2) $(LIBOBJS) $(CFLAGS)
clean:
	rm -f $(OBJS) $(OBJS2)  stm32flash
	cd parsers && $(MAKE) $@

install: all
	$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
	$(INSTALL) -m 755 stm32flash $(DESTDIR)$(PREFIX)/bin
	$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man1
	$(INSTALL) -m 644 stm32flash.1 $(DESTDIR)$(PREFIX)/share/man/man1

.PHONY: all clean install
